import sys
import os

project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
sys.path.append(project_root)

from pkg.client.client import Config
from pkg.client.client import Client
from pkg.invoke.invoke import *

if __name__ == '__main__':

    if os.getenv('CTYUN_AK') == None or os.getenv('CTYUN_SK') == None:
        print('Please set CTYUN_AK and CTYUN_SK environment variables')
        sys.exit(1)

    cfg = Config(
        endpoint='cf.fc-xinan1.ctyun.cn',
        accessKey=os.getenv('CTYUN_AK'),
        secretKey=os.getenv('CTYUN_SK'),
        protocol='https',
        method='POST',
    )

    c =Client(cfg)
    request = invoke_workflow_request(
        workflow_name='test1',
        input_data='{"key": "hello"}',
        execution_name='test1-execution',
    )
    region = "200000002368"
    invoke_svc = workflow_service(c)

    print(f"start example workflow invoke.")
    data = invoke_svc.invoke_workflow(region, request)
    print(f"example workflow invoke result: {data}")

